<template>
	<view>
		<!-- <button type="default" @click="onClick">测试</button> -->
		<!-- 一条新信息 -->
		<view @tap.stop="hideModal" class="cu-modal" :class="modalName=='true'?'show':''">
			<view class="cu-dialog" @click.stop="opneClick">
				<view class="cu-bar bg-white justify-end">
					<view class="content">有{{bigtotal}}条新消息</view>
				</view>
				<view class="padding-xl" v-if='wyBool' >
					<view class="cu-list menu-avatar" @click.stop="goYemian(item.body.talk_id)"  v-for='(item,index) in showData' :key='index'>
						<view class="cu-item">
							<view class="cu-avatar round lg" style='background-image:url(https://ossweb-img.qq.com/images/lol/web201310/skin/big1000.jpg);'></view>
							<view class="content">
								<view class="text-grey">{{item.head.fromMemberId}}</view>
								<view class="text-gray text-sm flex">
									<view class="text-cut">
										{{item.body.content instanceof Object ? item.body.content.title : item.body.content}}
									</view>
								</view>
							</view>
							<view class="action">
								<view class="text-grey text-xs">{{item.head.dateTime}}</view>
								<view class="cu-tag round bg-grey sm">{{item.total}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				showData:[],
				memberId:'',
				bigtotal:0,
				list:[],
				// 是否展示一条新消息详情
				wyBool: false,
				modalName:false,
				modalName2:false,
			}
		},
	
		methods:{
			// 一条新消息详情单击事件
			opneClick (){
				this.wyBool = !this.wyBool
			},
			// 弹框 
			showModal(data,member_id) {
                console.log(data,'传来的数据');
                this.bigtotal = 0
				this.memberId = member_id
				let sign=0
				this.showData.map((item,index)=>{
					if(data.body.talk_id==item.body.talk_id){
						sign=1;
						this.showData[index].total++;
						this.showData[index].body.content = data.body.content
					}
				})
				if(sign===0){
					data['total']=1;
					this.showData.push(data)
                }
                this.showData.map((item)=>{
                    this.bigtotal += item.total * 1
                })
				console.log(this.showData,'弹框内数据')
                this.modalName = 'true'
			},
			// 关闭弹框
			hideModal() {
				this.showData = []
				this.modalName = 'false'
                this.wyBool = false
                this.bigtotal= 0
			},
			// 去聊天页
			goYemian (id){
				uni.navigateTo({
					url:'../../pages/talk/chat?id='+id
				})
			}
		}
		}
</script>
	
<style scoped>
	.cu-dialog {
		top: 100rpx;
		left: 40rpx;
		position: fixed;
	}
	.cuIcon-unfold:before{
		position: absolute;
		top: 28rpx;
		right: 120rpx;
	}
</style>
